package designPattern.flyweight;

import java.util.Hashtable;

public class CharacterFactory {
	private Hashtable characters = new Hashtable();

    public Character GetCharacter(char key)
    {
      // Uses "lazy initialization"
      Character character = (Character)characters.get(key);
      if (character == null)
      {
        switch (key)
        {
          case 'A': character = new CharacterA(); break;
          case 'B': character = new CharacterB(); break;
            //
          case 'Z': character = new CharacterZ(); break;
        }
        characters.put(key, character);
      }
      return character;
    }
}
